package com.example.user1.controller;

import com.example.user1.cmd.ModifyProfilePictureCmd;
import com.example.user1.cmd.UserInfoCmd;
import com.example.user1.cmd.UserInfoModifyCmd;
import com.example.user1.service.UserService;
import com.example.user1.vo.Result;
import com.example.user1.vo.UserInfoVo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @GetMapping("/listAll")
    public Result<List<UserInfoVo>> listALl() {
        return Result.success(userService.list());
    }

    @PostMapping("/add")
    public Result<Integer> add(@RequestBody @Valid UserInfoCmd cmd) {
        return Result.success(userService.add(cmd));
    }

    @GetMapping("/self")
    public Result<UserInfoVo> get() {
        return Result.success(userService.self());
    }

    @PostMapping("/modify")
    public Result<Integer> modify(@RequestBody @Valid UserInfoModifyCmd cmd) {
        userService.modify(cmd);
        return Result.success();
    }
    @PostMapping("/modify/profilePicture")
    public Result<String> modifyProfilePicture(@RequestBody @Valid ModifyProfilePictureCmd cmd){
        userService.modifyProfilePicture(cmd);
        return Result.success();
    }
}
